<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>角色权限</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="${pageContext.request.contextPath }/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/animate.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/plugins/iCheck/custom.css" rel="stylesheet">
</head>
<body class="gray-bg">
    <div class="wrapper animated fadeInRight">
        <div class="row">
            <div>
                <div class="ibox float-e-margins">
                    <div class="ibox-content" style="overflow:hidden;">
                        <form class="form-horizontal col-sm-12" id="signupForm">
                        	<input type="hidden" value="${rId}" id="rId" name="rId">
                        	<div class="form-group">

                                    <c:forEach items="${auList }" var="list">
										<label class="checkbox-inline i-checks" style="width:165px;">
                                        <input type="checkbox" name="checkbox"
										<c:forEach items="${roAuList }" var="rl">
										<c:if test="${rl.ARA_AUTHORITYID==list.id }">checked="checked"</c:if>
										</c:forEach >
										 value="${list.id }">${list.authority }</label>
									</c:forEach>

                            </div>
                            <div class="form-group">
                                <div class="text-center">
                                    <button class="btn btn-primary" onclick="saveAuth();" type="button">保存</button>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <button class="btn btn-primary" onclick="cancel();">取消</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 全局js -->
    <script src="${pageContext.request.contextPath }/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <script src="${pageContext.request.contextPath }/js/content.js?v=1.0.0"></script>
    <!-- jQuery Validation plugin javascript-->
    <script src="${pageContext.request.contextPath }/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/plugins/validate/messages_zh.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/plugins/layer/layer.min.js"></script>
    <!-- iCheck -->
    <script src="${pageContext.request.contextPath }/js/plugins/iCheck/icheck.min.js"></script>
    <script>
        $(document).ready(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        });
    </script>
    <script type="text/javascript">
  //全选
    function checkAll(obj){
        $("input[name='checkbox']").prop('checked', $(obj).prop('checked'));
    }
    //保存
    function saveAuth(){
    	var str=$('input:checkbox[name=checkbox]');
    	var objarray=str.length;
    	var a = new Array();
    	var idStr="";
    	for (i=0;i<objarray;i++){
    	  if(str[i].checked == true){
    	  	idStr+=str[i].value+",";
    	  }
    	}
    	$.ajax({
            type: "POST",
            url: "${pageContext.request.contextPath}/admin/role/saveAuth",
            data: {'idStr':idStr,'rId':$("#rId").val()},
            dataType: "json",
            success: function(data){
            	if(data.code==1){
					layer.msg('保存成功！',{time: 2000,icon:1});
					setTimeout('cancel()',3000);
				}else if(data.code==0){
					layer.msg('保存失败！',{icon:0});
				}else{
					layer.msg('对不起！你没有权限！',{icon:0});
				}
            }
        });
    }
  	//取消
    function cancel(){
   	 	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.close(index);
    }
    </script>
</body>
</html>